#include "playerPseudo.h"
#include "joinGame.h"
#include "player.h"
#include "protocolNetwork.h"

int incPlayer = 0;

Player::Player(unsigned int readCirbufSize, unsigned int writeCirbufSize) :
  _socket(new PortableSocket),
  _readBuf(readCirbufSize),
  _writeBuf(writeCirbufSize),
  _proto(new protocol),
  _poolTime(new poolTime)
{
  _id = incPlayer++;
  _manager = false;
  _ready = false;
  _away = false;
  this->_proto->registerSlot(protocol::PLAYER_PSEUDO, new playerPseudo);
  this->_proto->registerSlot(protocol::JOIN_GAME, new joinGame);
}

Player::Player(PortableSocket *sock, unsigned int readCirbufSize, unsigned int writeCirbufSize) :
  _socket(sock),
  _readBuf(readCirbufSize),
  _writeBuf(writeCirbufSize),
  _proto(new protocol),
  _poolTime(new poolTime)
{
  _id = incPlayer++;
  _manager = false;
  _ready = false;
  _away = false;
  this->_proto->registerSlot(protocol::PLAYER_PSEUDO, new playerPseudo);
  this->_proto->registerSlot(protocol::JOIN_GAME, new joinGame);
}

std::string const &Player::getName() const
{
    return (_name);
}

void Player::setName(std::string const &name)
{
    _name = name;
}

int Player::getId() const
{
  return (_id);
}

std::string Player::getIp() const
{
  return (_ip);
}

protocol	*Player::getProto()
{
  return (_proto);
}

void Player::setId(int id)
{
  _id = id;
}

void Player::setIp(std::string const &ip)
{
  _ip = ip;
}

bool Player::isManager() const
{
  return (_manager);
}

void Player::setManager(bool m)
{
  _manager = m;
}

bool Player::isReady() const
{
  return (_ready);
}

void Player::setReady(bool r)
{
  _ready = r;
}

PortableSocket *Player::getSocket()
{
    return (_socket);
}

void Player::setSocket(PortableSocket *sock)
{
    _socket = sock;
}

CircularBuffer *Player::getReadBuffer()
{
    return (&_readBuf);
}

CircularBuffer *Player::getWriteBuffer()
{
    return (&_writeBuf);
}

bool Player::isAway() const
{
  return (this->_away);
}

void Player::setAway(bool a)
{
  this->_away = a;
}
